package jobs;

import java.awt.geom.Area;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;

import models.Area_loc;
import models.CarReturnReport;
import models.Contract;
import models.OperationReport;
import models.Product;
import models.User;
import play.jobs.Job;
import play.jobs.OnApplicationStart;

@OnApplicationStart
public class Bootstrap extends Job {
	

	public void doJob() {
		/*	Product.deleteAll();
		Contract.deleteAll();
		Area_loc.deleteAll();
		CarReturnReport.deleteAll();
		OperationReport.deleteAll();
		
		Area_loc a1 = new Area_loc("sat","zmalek");
		Area_loc a2 = new Area_loc("sun","zatoon");
		a1.save();
		a2.save();
		Calendar cal = Calendar.getInstance(); // Get the current date
		cal.clear(Calendar.HOUR);
		cal.clear(Calendar.MINUTE);
		cal.clear(Calendar.SECOND);
		cal.clear(Calendar.MILLISECOND);
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MMM/dd"); // format
																			// it
																			// as
																			// per
																			// your
																			// requirement
		String dateNow = formatter.format(cal.getTime());
		User.deleteAll();
		Product.deleteAll();
		CarReturnReport.deleteAll();
		OperationReport.deleteAll();
		Contract.deleteAll();

		User remon = new User("Remon", "4");
		remon.save();
		Date date = cal.getTime();
		for (int count = 0; count < 10; count++) {
			ArrayList<Product> productList = new ArrayList<Product>();
			Product p1 = new Product("Mop18", 5, 4, 10, "frawlaa",
					new LinkedList<Date>(), "HDF");
			p1.addChangeTimes(p1, 4, date);
			p1.save();
			productList.add(p1);

				//System.out.println("all contaracts " + Contract.findAll().size());
				Contract c = new Contract("Michael", "Ibraam", "01206535301",
						"01225319339", "0235698658", "0235680286", "sa", 400+count,
						12, date, "19 7mada street", "mozaykooo", productList);
				c.save();
				
				for (int i = 0; i < productList.size(); i++) {
					productList.get(i).contract = c;
					productList.get(i).save();
				}
				c.productList = productList;
				c.save();
				

			
		}

		

		 */
		
		// org.hsqldb.util.DatabaseManagerSwing.main(new String[] { "--url","jdbc:hsqldb:fs:playembed", "--noexit" });
	}
	
	

}
